package person.learn.thymeleaf;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * 1.使用Thymeleaf作为模板引擎,要在application.yml里设置spring.thymeleaf.caching设置为false
 * 2.用了模板引擎之后,原先对于jsp的设置无效
 * 3.(idea编辑器需要手动点击CTRL+F9,手动编译,因为IDEA文件不需要手动保存)修改Thymeleaf模板的内容后,要不重启项目就生效的话,需要make一下,
 * 或者使用热部署:http://mamicode.com/info-detail-1346413.html
 * 4.要使用Thymeleaf模板 请将pom.xml中相应的jar依赖注释去掉
 * Created by barton on 16-5-19.
 */
@Controller
public class ThymeleafController {

    @RequestMapping("/thymeleaf")
    public String index(Model model) {
        Person single = new Person("aa", 11);

        List<Person> people = new ArrayList<>();

        Person p1 = new Person("xx", 11);
        Person p2 = new Person("yy", 22);
        Person p3 = new Person("zz", 33);

        people.add(p1);
        people.add(p2);
        people.add(p3);

        model.addAttribute("singlePerson", single);
        model.addAttribute("people", people);

        return "thymeleaf/thymeleaf";
    }
}
